<% /* $Id: submission.jsp 132 2011-08-26 10:23:42Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="header.jsp" %>

<%

	SubmissionFull submissionFull = SubmissionsModel.getSubmissionFull(Long.parseLong(request.getParameter("submission_id")));
	if (null == submissionFull)
	{
%>
		
	<h2 align="center">Розвязок не знайдено</h2>
<%
	}
	else if (submissionFull.getSubmissionEntry().getDjudgeFlag().intValue() <= 0)
	{
%>
		<h2 align="center">Розвязок ще не перевірено</h2>
<%
	}
	else
	{
		if (!(contestUser.isJudge() || (contest.getShowFullSubmissions() && submissionFull.getSubmissionEntry().getUserId().equals(user.getId()))))
		{
%>
			<h2 align="center">Доступ заборонено</h2>
<%
		}
		else
		{
%>
	<h2><a href="<%= Linker.link("contests/source.jsp?contest_id=" + contest.getId() + "&submission_id=" + submissionFull.getSubmissionEntry().getId()) %>">Текст програми</a></h2>
<%
			Document doc = DJudgeUtils.getDocumentFromString(submissionFull.getSubmissionDetailsEntry().getXmlReport());
			Element elem = doc.getDocumentElement();
			String judgement = elem.getAttribute("result");
			
			{
				NodeList compilation = elem.getElementsByTagName("compilation");
				String compilerOutput = "N/A";
				if (compilation.getLength() > 0)
				{
					compilerOutput = ((Element)compilation.item(0)).getAttribute("compiler-output");
				}
%>
	<h3>Вивід компілятора</h3>
	<pre><%= compilerOutput %></pre>
<%
			}
			if (!"CE".equals(judgement))
			{
				NodeList problem = elem.getElementsByTagName("problem");
				NodeList groups = ((Element)problem.item(0)).getElementsByTagName("group");
				%>
				<table>
				<%
				for (int ig = 0; ig < groups.getLength(); ig++)
				{
					%>
					<tr>
					<td>
						<%= "<font color='red'><h3 align='center'>" + (ig == 0 ? "Тести з умови" : "Тести журі") + "</h3></font>" %>
						<table>
							<tr>
								<th>Тест</th>
								<th>Час роботи</th>
								<th>Обсяг пам'яті</th>
								<th>Результат перевірки</th>
								<th>Бали</th>
								<%= user.isAdmin() ? "<th>Validator</th>" : "" %>
							</tr>
					<%
					NodeList tests = ((Element)groups.item(ig)).getElementsByTagName("test");
					for (int it = 0; it < tests.getLength(); it++)
					{
						Element test = (Element) tests.item(it);
						String j = test.getAttribute("result"), rowColor;
						if ("AC".equals(j))
							rowColor = "#aaffaa";
						else if ("WA".equals(j) || "TLE".equals(j) || "RE".equals(j))
							rowColor = "#ffaaaa";
						else
							rowColor = "#777777";
						%>
						<tr align="center" bgcolor="<%= rowColor %>">
							<td><%= it+1 %></td>
							<td><%= test.getAttribute("max-time") %> ms</td>
							<td><%= test.getAttribute("max-memory") %> bytes</td>
							<td><%= Formatters.formatJudgement(test.getAttribute("result")) %></td>
							<td><%= test.getAttribute("score") %></td>
							<%
								if (contestUser.isJudge())
								{
									NodeList validator = ((Element)test).getElementsByTagName("checker");
									%>
									<td><%= StringEscapeUtils.escapeHtml(StringEscapeUtils.unescapeXml(((Element)validator.item(0)).getAttribute("output"))) %></td>
									<%
								}
							%>
						</tr>
						<%
					}
					%>
					</table></td></tr>
					<%
					
				}
				%>
				</table>
				<%
			}
			if (contestUser.isJudge())
			{
				%>
<hr />
<pre>
<%= StringEscapeUtils.escapeXml(submissionFull.getSubmissionDetailsEntry().getXmlReport().toString()) %>
</pre>
				<%
			}
		}
	}
%>

<%@ include file="footer.jsp" %>
